<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力中小企业发展 
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德代驾系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
+---------------------------------------------------------------------- -->

<script>
	export default {
		globalData: {
			// 接口地址
			adminPath: "https://lhdj.ncscloudmedia.com/index.php",
			// 可预约天数
			appointmentDays: 4,
			// 预订单数据
			advanceOrder: {},
			// 是否显示首页优惠券
			showIndexCoupon: false,
		},
		onLaunch: function(e) {
			// #ifdef MP-WEIXIN
			// 微信版本更新
			if (wx.canIUse('getUpdateManager')) {
				const updateManager = wx.getUpdateManager()
				if (updateManager && updateManager.onCheckForUpdate) {
					updateManager.onCheckForUpdate(function(res) {
						// 请求完新版本信息的回调
						if (res.hasUpdate) {
							updateManager.onUpdateReady(function() {
								wx.showModal({
									title: '更新提示',
									content: '新版本已经准备好，是否重启应用？',
									success: function(res) {
										if (res.confirm) {
											updateManager.applyUpdate()
										}
									}
								})
							})
							updateManager.onUpdateFailed(function() {
								wx.showModal({
									title: '已经有新版本了哟~',
									content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
								})
							})
						}
					})
				}
			} else {
				wx.showModal({
					title: '提示',
					content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
				})
			}
			// #endif
			this.$store.commit('app/setCurrentCity', uni.getStorageSync("currentCity") || "")
			if (!uni.getStorageSync("soundAndVibrate")) {
				uni.setStorageSync("soundAndVibrate", { soundOpen: true, vibrateOpen: true })
			}
			// 设置登录信息
			const token = uni.getStorageSync("token")
			if (token) {
				const userInfo = uni.getStorageSync("userInfo")
				this.$store.commit('user/setToken', token)
				this.$store.commit('user/setUserInfo', userInfo)
			}
			this.getConfig(e.path)
		},
		onShow: function() {},
		onHide: function() {},
		methods: {
			// 获取系统配置
			getConfig(path) {
				this.$util.request("main.config", {}, { baseURL: this.globalData.adminPath }).then(res => {
					if (res.code == 1) {
						this.$store.commit('app/setConfig', {
							themeColor: res.data.theme_colors,
							appletName: res.data.applet_name,
							loginImg: res.data.login_img,
							statement: res.data.applet_record_number,
							shareTitle: res.data.share_title,
							shareImage: res.data.share_image,
							version: res.data.version,
							tencentMapKey: res.data.tencent_map_web_service_key,
							websocketPort: res.data.websocket_port,
							domain: res.data.domain,
							inviteCashbackStatus: res.data.invite_cashback_status,
							subscribeNotifyIds: res.data.subscribe_msg_tpl_ids,
							newOrderNotice: res.data.new_order_notice,
							cancelOrderNotice: res.data.cancel_order_notice,
						})
						if (res.data.coupon_show_status == 1) this.globalData.showIndexCoupon = true
						else this.globalData.showIndexCoupon = false
						if (path == "pages/passenger/index/index" && uni.getStorageSync("token")) {
							this.getDriverInfo()
						} else {
							this.$isResolve()
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(error => {
					console.error("获取配置信息", error)
				})
			},
			// 获取司机信息
			getDriverInfo() {
				this.$util.request("driver.user", {}, { baseURL: this.globalData.adminPath }).then(res => {
					if (res.code == 1) {
						if (res.data.certification_examine_status == 2) {
							uni.setStorageSync("driverInfo", res.data)
							this.$store.commit('user/setDriverInfo', res.data)
							this.$store.commit('app/setDriverSocket', 1)
							uni.reLaunch({
								url: "/pages/driver/index/index",
								success: () => {
									this.$isResolve()
								}
							})
						} else this.$isResolve()
					} else {
						this.$isResolve()
					}
				}).catch(error => {
					this.$isResolve()
					console.error('获取司机信息 ', error)
				})
			},
		},
	}
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	/*每个页面公共css */

	page {
		color: #242629;
		background: #F6F7FB;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}

	image {
		display: block;
		width: 100%;
		height: 100%;
	}

	view,
	scroll-view {
		box-sizing: border-box;
	}

	button::after {
		border: none;
	}

	button.clear {
		padding: 0;
		margin: 0;
		border: none;
		background: transparent;
		line-height: 1.3;
	}

	button.clear::after {
		display: none;
	}

	.flex {
		display: flex;
	}

	.flex-inline {
		display: inline-flex;
	}

	.flex-column {
		display: flex;
		flex-direction: column;
	}

	.flex-item {
		flex: 1;
		min-width: 0;
	}

	.flex-wrap {
		flex-wrap: wrap;
	}

	.align-items-center {
		align-items: center;
	}

	.align-items-start {
		align-items: flex-start;
	}

	.align-items-end {
		align-items: flex-end;
	}

	.justify-content-between {
		justify-content: space-between;
	}

	.justify-content-around {
		justify-content: space-around;
	}

	.justify-content-center {
		justify-content: center;
	}

	.justify-content-start {
		justify-content: flex-start;
	}

	.justify-content-end {
		justify-content: flex-end;
	}

	.flex-center {
		justify-content: center;
		align-items: center;
	}

	.flex-between-center {
		justify-content: space-between;
		align-items: center;
	}

	.flex-around-center {
		justify-content: space-around;
		align-items: center;
	}

	.text-center {
		text-align: center;
	}

	.text-ellipsis {
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		word-break: break-all;
	}

	.text-ellipsis-more {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		overflow: hidden;
		-webkit-line-clamp: 2;
		word-break: break-all;
	}

	.safe-padding {
		width: 100%;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}

	/* #endif */
</style>